from hashlib import md5
from os import PathLike
from pathlib import Path
from typing import Union
from io import BytesIO
from .upload2piclab import upload

__all__ = (
    'get_md5',
    'upload',
)

def get_md5(file: Union[str, PathLike, BytesIO]) -> str:
    """
    获取文件的MD5值
    :param file: 文件路径
    :return: MD5值
    """
    if isinstance(file, BytesIO):
        content = file.getvalue()
    else:
        if isinstance(file, str):
            file = Path(file)
        content = file.read_bytes()
    return md5(content).hexdigest()
